// var loginstatus = 0;//判断登录状态
namespace UserData {

    /************本地设置变量********/
    /**是否登录 */
    export let isLogin: boolean = false;
    /**用户cookie */
    export let Set_Cookie: any;
    /**是否开启音乐音效 */
    export let musicEnabled = true;
    /**用户当局游戏分数 */
    export let score=0;
    /**移动速度 */
    export let roleSpeed = {roleHorizontalSpeed:0,gravity:0,roleUpSpeed:0,roleDownSpeed:0,floorDownSpeed:0};
    export let roleNormalSpeed = {roleHorizontalSpeed:8,gravity:1,roleUpSpeed:18,roleDownSpeed:4,floorDownSpeed:5};
    export let roleHighSpeed = {roleHorizontalSpeed:8,gravity:2,roleUpSpeed:30,roleDownSpeed:8,floorDownSpeed:7};

    // export let roleNormalSpeed = {roleHorizontalSpeed:8,gravity:0.5,roleUpSpeed:30,roleDownSpeed:7,floorDownSpeed:5};
    // export let roleHighSpeed = {roleHorizontalSpeed:8,gravity:1,roleUpSpeed:40,roleDownSpeed:6,floorDownSpeed:10};
    export let deadTimes = 0;
    /************用户基本信息********/
    /**用户头像 暂时使用不到也拿不到微信数据*/
    export let avatar: string = '';
    /**用户昵称 暂时使用不到也拿不到微信数据*/
    export let nickname: string = '';
    /**用户性别 暂时使用不到也拿不到微信数据*/
    export let gender = '';

    /**用户ID */
    export let id: number = 0;
    /**服务器端钻石数量 */
    export let rocketCardNum = 1;
    export let speedCardNum = 1;
    export let diamondNum = 0;
    /**当局游戏钻石 */
    export let gameDiamondNum = 0;
    /**历史累计最高分*/
    export let highest_score:number = 0;
    /**本周最高分*/
    export let week_highest_score = 0;
    /**复活币数量*/
    export let reborn_coin = 0;
    /**是否已解锁足球小子皮肤 */
    export let unlock_fbboy:boolean = false;
    /**解锁足球小子需要的钻石数量 */
    export let fbboy_cost:number = 999;
    /**兑换复活币的价格 */
    export let relive_cost:number = 22;
    /**当前的皮肤信息，球的信息 */
    export let current_ball = {
        id:1,/**球的id，会通过id获取图片*/
        heart:1, /**红心数*/
        type:0 /**类型，0:球或者1:人 */
    }
    /**当前的装备技能，包含：砖石爆率、时间减速、红心数 */
    export let current_outfit = {
        heart:0, /**红心数*/
        heartPrice:300, /**下一级减速价格*/
        diamondRate:1.5,/**砖石爆率*/
        diamondRatePrice:300, /**下一级减速价格*/
        timeRate:"0.8", /**时间减速*/
        timeRatePrice:3000 /**下一级减速价格*/
    }
    export let current_bgId = "1";
    /**是否新纪录 */
    export let score_isWIN: boolean = false;
    // 上次打破记录的日期
    export let last_score_isWin_Date: string = "";

    export let hasGiftPackage:boolean = false;
    

    /**********后台配置信息*************/
    /**是否是审核状态 */ 
    export let is_verify = true;
    /**是否展示客服按钮*/
    export let customer = {show:false,path:"",image:"",title:""};
    /**是否展示更多游戏入口,游戏盒子*/
    //export let more_game = {show:false,image:""};
     export let more_game = {isjump:false,image:"",preview_image:"",wxapp:{appid:"",extraData:"",path:"",version:""}};
    /**是否展示复活币 */
    export let show_reborn_coin = true;
    /**是否展示游戏圈 */
    export let show_game_circle = false;
    /**复活币弹窗说明模式*/
    export let relive_type:string = "give";
    

    




    export function saveUserInfo(data:any){
        if(!data || !data.info)return;
        // id
        UserData.id = data.user_id;
        UserData.avatar = data.avatar;
        UserData.nickname = data.nickname;
        UserData.gender = data.gender;
        
        // 历史最高分
        UserData.highest_score = data.info.highest_score;
        // 本周最高分
        UserData.week_highest_score = data.info.week_highest;
        // 复活币
        // UserData.reborn_coin = data.info.relive_coins;
        // UserData.unlock_fbboy = data.info.unlock_fbboy;
        // UserData.fbboy_cost = data.info.fbboy_cost;
        // UserData.relive_cost = data.info.relive_cost;

        // UserData.current_outfit = {
        //     heart:data.info.love_star,
        //     heartPrice:data.info.love_star_cost,
        //     diamondRate:data.info.burst_rate,
        //     diamondRatePrice:data.info.burst_rate_cost,
        //     timeRate:data.info.slow_down,
        //     timeRatePrice:data.info.slow_down_cost
        // };
        // UserData.current_ball = {
        //     id:data.curskin.inused,
        //     heart:data.curskin.love_star,
        //     type:data.curskin.type
        // };
        
        // 持久化保存
        Utils.saveItem2Storage(GameConstants.saveUserInfoKey,data);

       // UserData.initSkinList();
    }
    export function initSkinList(){
        let data = UserData.getSkinList();
        if(!data){
            App.HttpRequestManager.request(NetConstants.SKIN_LIST, "", function(res){
                if(res && res.statusCode == 200 && res.data.code == 0){
                    UserData.saveSkinList(res.data.data);
                }
            }, egret.HttpMethod.GET);
        }
    }
    export function saveSkinList(data){
        Utils.saveItem2Storage(GameConstants.saveShowSkinListKey, data);
    }
    export function getSkinList():any{
        let data:any = Utils.getItemFromStorage(GameConstants.saveShowSkinListKey);
        return data;
    }
    /**将某些信息持久化 */
    export function save2Local(){
        Utils.saveItem2Storage(GameConstants.saveShowMusicKey, UserData.musicEnabled+"");
        Utils.saveItem2Storage(GameConstants.saveLastCutTheRecordDateKey, UserData.last_score_isWin_Date);
        //Utils.saveItem2Storage(GameConstants.saveUserChoiceBgImgIdKey, UserData.current_bgId);
        
    }
    export function saveConfig(data:any){
        if(!data)return;
        UserData.is_verify = data.is_verify;
        // 客服
        UserData.customer = data.customer;
        // 更多游戏进入游戏盒子
        UserData.more_game = data.more_game;
        // 持久化保存
        Utils.saveItem2Storage(GameConstants.saveUserConfigKey,data);
    }
    export function initData(){
        let data:any = Utils.getItemFromStorage(GameConstants.saveUserInfoKey);
        let configData:any = Utils.getItemFromStorage(GameConstants.saveUserConfigKey);
        if(data){
            // id
            UserData.id = data.user_id;
            UserData.avatar = data.avatar;
            UserData.nickname = data.nickname;
            UserData.gender = data.gender;
            
            // 钻石
            UserData.diamondNum = data.info.diamonds;
            // 历史最高分
            UserData.highest_score = data.info.highest_score;
            // 本周最高分
            UserData.week_highest_score = data.info.week_highest;
            // 复活币
            UserData.reborn_coin = data.info.relive_coins;
            UserData.unlock_fbboy = data.info.unlock_fbboy;
            UserData.fbboy_cost = data.info.fbboy_cost;
            UserData.relive_cost = data.info.relive_cost;

            UserData.current_outfit = {
                heart:data.info.love_star,
                heartPrice:data.info.love_star_cost,
                diamondRate:data.info.burst_rate,
                diamondRatePrice:data.info.burst_rate_cost,
                timeRate:data.info.slow_down,
                timeRatePrice:data.info.slow_down_cost
            };
            UserData.current_ball = {
                id:data.curskin.inused,
                heart:data.curskin.love_star,
                type:data.curskin.type
            };
           
            
        }
        if(configData){
            UserData.is_verify = configData.is_verify;
            UserData.customer = configData.customer;
            UserData.more_game = configData.more_game;

        }

        // 本地保存的设置
        let musicEnabled:string = Utils.getItemFromStorage(GameConstants.saveShowMusicKey);
        if(musicEnabled == "false"){
            UserData.musicEnabled = false;
        }else{
            UserData.musicEnabled = true;
        }
        // let current_bgId = Utils.getItemFromStorage(GameConstants.saveUserChoiceBgImgIdKey);
        // if(current_bgId){
        //     UserData.current_bgId = current_bgId;
        // }else{
        //    // UserData.current_bgId = "1";
        // }
        let last_score_isWin_Date:string = Utils.getItemFromStorage(GameConstants.saveLastCutTheRecordDateKey);
        UserData.last_score_isWin_Date = last_score_isWin_Date;
    }

    export let RebornType={
		GIVE:"give",
		SHARE:"share"
	}
    /**
     * 获取发送到共享数据域的基本数据
     */
    export function getMineOpenData(){
        let mineData = {
                        id:""+UserData.id,
                        score:UserData.score,
                        week_highest_score:UserData.week_highest_score,
                        highest_score:UserData.highest_score,
                        shareTicket:GameConfig.shareTicket
                        };
        return mineData;
    }
}